#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2019/10/1 17:53
# @Author  : 十年
# @Site    : https://gitee.com/chshao/aiplotest
# @CSDN    : https://blog.csdn.net/m0_37576542?type=blog
# @File    : AutoLogging.py
# @Software: PyCharm
import os
import sys
import logging
import traceback
from autotest.kernel.logger.AutoLogger import AutoLogger


def addProjectLog():
    """读取工程配置文件后调用"""
    from autotest.kernel.modle.Variable import Var
    AutoLogger().beginProjectLog(Var.Project.ReportPath, logging.INFO)


def removeProjectLog():
    """工程执行结束后调用"""
    AutoLogger().endProjectLog()


def addCaseLog():
    """用例开始前调用"""
    from autotest.kernel.modle.Variable import Var
    caseName = Var.Case.CaseID
    caseLogPath = os.path.join(Var.Project.ReportPath, 'log')
    AutoLogger().beginCaseLog(caseLogPath, caseName, logging.INFO)


def removeCaseLog():
    """用例结束后调用"""
    AutoLogger().endCaseLog()


class Log(object):

    @staticmethod
    def debug(msg):
        AutoLogger().debug(msg)

    @staticmethod
    def info(msg):
        AutoLogger().info(msg)

    @staticmethod
    def error(msg):
        AutoLogger().error(msg)

    @staticmethod
    def warn(msg):
        AutoLogger().warn(msg)

    @staticmethod
    def critical(msg):
        AutoLogger().critical(msg)

    @staticmethod
    def traceback(msg=''):
        AutoLogger().error("{}, {}".format("".join(traceback.format_exception(*sys.exc_info())), msg))
